package com.zg.shop.category;

import java.util.List;

import com.opensymphony.xwork2.ActionContext;
import com.opensymphony.xwork2.ActionSupport;
import com.opensymphony.xwork2.ModelDriven;

public class CategoryAction extends ActionSupport implements ModelDriven<Category>{
	private CategoryService categoryService;
	private Category category = new Category();
	
	public void setCategoryService(CategoryService categoryService) {
		this.categoryService = categoryService;
	}
	
	@Override
	public Category getModel() {
		return category;
	}

	public String adminFindAll(){
		List<Category> categorys = categoryService.findAll();
		ActionContext.getContext().getValueStack().set("categorys", categorys);
		
		return "adminFindAllSuccess";
	}
	public String save(){
		categoryService.save(category);
		return "saveSuccess";
	}

	public String delete(){
		categoryService.delete(category);
		return "deleteSuccess";
	}
	public String edit(){
		category = categoryService.findByCid(category.getCid());
		
		return "editSuccess";
	}
	public String update(){
		categoryService.update(category);
		return "updateSuccess";
	}
	
}
